package org.jason.minio.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jason.minio.service.PictureService;
import org.jason.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/picture")
@Api(tags = "图片上传模块", value = "PictureController")
public class PictureController {

    @Autowired
    private PictureService pictureService;

    //上传头像
    @ApiOperation("上传头像")
    @PostMapping("/upload/avatar")
    @SaCheckLogin
    public ResponseResult uploadAvatar(@RequestParam("file") MultipartFile file) throws Exception {
        return pictureService.uploadAvatar(file);
    }

    //根据id获取用户头像
    @ApiOperation("根据id获取用户头像")
    @GetMapping("/avatar/{userId:^[1-9]\\d*$}")
    public ResponseResult getAvatar(@PathVariable String userId) {
        return pictureService.getAvatar(userId);
    }
}
